home *** CD-ROM | disk | FTP | other *** search
- Path: ccshst05.cs.uoguelph.ca!ccshst01!thay
- From: thay@uoguelph.ca (Toby K Hay)
- Newsgroups: comp.lang.c
- Subject: Re: help rand !
- Date: 18 Apr 1996 17:53:58 GMT
- Organization: University of Guelph
- Distribution: world
- Message-ID: <4l5vjm$5lj@ccshst05.uoguelph.ca>
- References: <4l5d75$mes@usenetp1.news.prodigy.com> <4l5fj4$1ehs@serra.unipi.it>
- NNTP-Posting-Host: ccshst01.uoguelph.ca
- X-Newsreader: TIN [version 1.2 PL2]
-
- Maurizio Loreti (loreti@mxsld2.pd.infn.it) wrote:
- : In article <4l5d75$mes@usenetp1.news.prodigy.com>, UNCK19A@prodigy.com (Thomas Furka) writes:
- : >I AM WRITING A PROGRAM FOR SCHOOL THAT PICKS 12 RANDOM NUMBERS. COULD
- : >SOME ONE PLEASE HELP ME SO THAT I DON'T GET ANY DUPLICATES. I AM PICKING
- : >FROM THE COMPUTER CLOCK(<TIME.H> USING SRAND.
-
- : Don't shout; we are not blind.
- This is a disguised request to use upper case in only the usual places.
-
- 1) Use srand() only once to initialize the sequence of random numbers -
- use rand() to get the random numbers.
-
- 2) To avoid duplicates in a set of 12 numbers simply check that each
- new one isn't already in the list. Since the range of random number
- returned by rand() is 0 to at least 30,000 on most systems you're
- unlikely get any duplicates in the first 12.
-
- 3) If this isn't what you meant (as seems likely) feel free to send me a
- note with a clearer question.
-
- Toby Hay thay@uoguelph
-